<div class="layui-fluid layui-anim febs-anim" id="febs-obj" lay-title="数据查询导出">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="obj-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">办理地址</label>
                                        <div class="layui-input-inline">
                                            <select id="addressType" name="addressType" >
                                                <option value=""></option>
                                                <option value="大厅">大厅</option>
                                                <option value="分厅">分厅</option>
                                                <option value="大厅/分厅">大厅/分厅</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">服务对象</label>
                                        <div class="layui-input-inline">
                                            <select id="serviceObject" name="serviceObject" >
                                                <option value=""></option>
                                                <option value="个人">个人</option>
                                                <option value="法人">法人</option>
                                                <option value="个人/法人">个人/法人</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">即办事项</label>
                                        <div class="layui-input-inline">
                                            <select id="immediately" name="immediately" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">凭身份证办理：</label>
                                        <div class="layui-input-inline">
                                            <select id="needCard" name="needCard" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">通办事项：</label>
                                        <div class="layui-input-inline">
                                            <select id="allCityHandle" name="allCityHandle" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">最多跑一次：</label>
                                        <div class="layui-input-inline">
                                            <select id="atMostOnce" name="atMostOnce" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">零跑动：</label>
                                        <div class="layui-input-inline">
                                            <select id="zeroRun" name="zeroRun" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">是否网办：</label>
                                        <div class="layui-input-inline">
                                            <select id="onlineCheck" name="onlineCheck" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">上传日期</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="bussTime" id="bussTime" class="layui-input">
                                        </div>
                                    </div>


                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <!--<div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>-->
                            </div>
                        </div>
                    </form>
                    <button class="layui-btn  layui-btn-sm layui-btn-primary" id="export">
                        <i class="layui-icon">&#xe7a8;</i> 导出合计
                    </button>
                    <table class="layui-table" id="obj_table">
                        <colgroup>
                            <col width="100">
                            <col width="100">
                            <col width="100">
                            <col width="100">
                            <col width="150">
                            <col width="100">
                            <col width="100">
                            <col width="100">
                            <col width="100">
                            <col width="100">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>单位名称</th>
                            <th>主项</th>
                            <th>子项</th>
                            <th>事项类别</th>
                            <th>业务办理名称</th>
                            <th>咨询业务量</th>
                            <th>邮寄业务量</th>
                            <th>线上业务量</th>
                            <th>线下业务量-大厅</th>
                            <th>线下业务量-分厅</th>
                        </tr>
                        </thead>
                        <tbody id="obj_table_tbody">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="obj-option">
    <a lay-event="detail" ><i
                class="layui-icon febs-edit-area febs-green">&#xe7a5;</i></a>
    <a lay-event="edit" ><i
                class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>
    <a lay-event="del" ><i class="layui-icon febs-edit-area febs-red">&#xe7f9;</i></a>
</script>
<script type="text/html" id="dataType">
    {{#
    var dataType = {
    1: {title: '部门'},
    0: {title: '事项'}
    }[d.dataType];
    }}
    <span>{{ dataType.title }}</span>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'treeSelect'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#febs-obj'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns;

        form.render();
        laydate.render({
            elem: '#bussTime',
            range: true,
            trigger: 'click'
        });
        initTable();

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('objTable');
                if (name === 'add') {
                    febs.modal.open('新增', 'hallUpData/add', {
                        btn: ['提交', '重置'],
                        area: $(window).width() <= 750 ? '95%' : '50%',
                        yes: function (index, layero) {
                            $('#obj-add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#obj-add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的记录');
                    } else {
                        febs.modal.confirm('删除', '确定删除该条记录？', function () {
                            var objIds = [];
                            layui.each(checkStatus.data, function (key, item) {
                                objIds.push(item.id)
                            });
                            deleteobjs(objIds.join(','));
                        });
                    }
                }
            },
            /*options: [{
                name: 'add',
                title: '新增'
            }, {
                name: 'delete',
                title: '删除'
            }]*/
        });


        table.on('tool(objTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                febs.modal.confirm('删除', '确定删除该条记录？', function () {
                    deleteobjs(data.id);
                });
            }
            if (layEvent === 'edit') {
                febs.modal.open('修改', 'hallUpData/update/' + data.id, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#obj-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });

        table.on('sort(objTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            /*var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});*/
            initTable();
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            initTable();
            //tableIns.reload({where: getQueryParams(), page: {curr: 1}});
        });
        $view.on('click', '#export', function () {
            var params = getQueryParams();
            febs.download(ctx +'resultData/exportInfo', params, '业务上报信息.xlsx');
        });
        function initTable(){
            var params=getQueryParams();
            febs.get(ctx + 'hallUpData/resultData', params, function (data) {
                console.info(data);
                if(data.code==200){
                    var deptData=data.data;
                    var tbodyHtml='';
                    for(var j=0;j<deptData.length;j++){
                        var d=deptData[j].dataList;
                        for(var i=0;i<d.length;i++){
                            tbodyHtml+='<tr>';
                            tbodyHtml+='<td>'+d[i].departName+'</td>';
                            tbodyHtml+='<td>'+d[i].mainItemName+'</td>';
                            tbodyHtml+='<td>'+d[i].sumItemName+'</td>';
                            tbodyHtml+='<td>'+d[i].itemType+'</td>';
                            tbodyHtml+='<td>'+d[i].itemName+'</td>';
                            if(i==0){
                                tbodyHtml+='<td rowspan="'+d.length+'">'+d[i].seekBussCount+'</td>';
                                tbodyHtml+='<td rowspan="'+d.length+'">'+d[i].mailBussCount+'</td>';
                            }
                            tbodyHtml+='<td >'+d[i].onlineBussCount+'</td>';
                            tbodyHtml+='<td >'+d[i].underlineHall+'</td>';
                            tbodyHtml+='<td >'+d[i].underlineSubHall+'</td>';
                            tbodyHtml+='</tr>';
                        }
                    }
                    $("#obj_table_tbody").html(tbodyHtml);
                }
            });
        }

        function getQueryParams() {
            var buss_time_start,
                buss_time_end,
                bussTime = $searchForm.find('input[name="bussTime"]').val();
            if (bussTime) {
                buss_time_start = bussTime.split(' - ')[0]+' 00:00:00';
                buss_time_end = bussTime.split(' - ')[1]+' 23:59:59';
            }
            return {
                buss_time_start:buss_time_start,
                buss_time_end:buss_time_end,
                addressType:  $searchForm.find('select[name="addressType"]').val(),
                serviceObject: $searchForm.find('select[name="serviceObject"]').val(),
                immediately:$searchForm.find('select[name="immediately"]').val(),
                needCard:  $searchForm.find('select[name="needCard"]').val(),
                allCityHandle:  $searchForm.find('select[name="allCityHandle"]').val(),
                atMostOnce:  $searchForm.find('select[name="atMostOnce"]').val(),
                zeroRun:  $searchForm.find('select[name="zeroRun"]').val(),
                onlineCheck:  $searchForm.find('select[name="onlineCheck"]').val(),
            };
        }

        function deleteobjs(objIds) {
            febs.get(ctx + 'hallUpData/delete/' + objIds, null, function () {
                febs.alert.success('删除成功');
                $query.click();
            });
        }
    })
</script>